package club.justwill.single.Controller;

import club.justwill.single.Service.AuditService;
import club.justwill.single.Service.UserService;
import club.justwill.single.aspect.LoginRequired;
import club.justwill.single.assembler.UserAddressAssemble;
import club.justwill.single.assembler.UserAssemble;
import club.justwill.single.bean.*;
import club.justwill.single.helper.SmsHelper;
import club.justwill.single.impl.ToolsImpl;
import club.justwill.single.model.CoreConstants;
import club.justwill.single.model.JsonResponse;
import club.justwill.single.model.SecurityToken;
import club.justwill.single.model.ServiceChannel;
import club.justwill.single.persistence.document.MobileAuthCode;
import club.justwill.single.persistence.jpo.User;
import club.justwill.single.persistence.store.MobileAuthCodeStore;
import club.justwill.single.util.JsonResponseHelper;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * Created by xiangnan on 15-12-23.
 */

@RestController
@Scope(WebApplicationContext.SCOPE_SESSION)
public class AuditController extends BaseController {
    private static Logger logger = LoggerFactory.getLogger(AuditController.class);

    @Autowired
    private AuditService auditService;

    @LoginRequired
    @RequestMapping(value = URL_ADUIT_PROJECT, method = RequestMethod.POST, produces = CoreConstants.MIME_JSON)
    public JsonResponse senAuthCode(@RequestBody AuditBean auditBean) {
        JsonResponse obj = new JsonResponse();
        SecurityToken token = new SecurityToken(sessionState.getUserId());
        token.generateToken(sessionState);
        auditService.auditProject(obj,token,auditBean);
        if(JsonResponseHelper.isHasError(obj)) {
            obj.setFailed();
        } else {
            obj.setSuccessful();
        }
        return obj;
    }
}
